﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using LuaInterface;
using System;

namespace GMBase.UI
{
    public class GButton : Button
    {
        private LuaTable m_LuaTable;
        private LuaTable m_LuaArgs;
        private Action<LuaTable, Selectable, LuaTable> m_LuaClickHandler;

        public void SetClickHandler(LuaTable lua, Action<LuaTable, Selectable, LuaTable> handler, LuaTable args = null)
        {
            m_LuaTable = lua;
            m_LuaArgs = args;
            m_LuaClickHandler = handler;
            onClick.AddListener(BtnClick);
        }

        public void BtnClick()
        {
            if (m_LuaTable != null && m_LuaClickHandler != null)
            {
                m_LuaClickHandler(m_LuaTable, this, m_LuaArgs);
            }
        }
    }
}
